﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                let selected = $('#booklist').datagrid('getSelected');
                if (!selected) {
                    alert("请选择待修改的用户");
                } else {
                    $("#modify-id").textbox("setValue", selected.id);
                    $("#modify-name").textbox("setValue", selected.username);
                    $("#modify-email").textbox("setValue", selected.email);
                    $("#modify-phone").textbox("setValue", selected.phone);
                    $("#modify-interest").textbox("setValue", selected.interest);
                    $('#dd').dialog('open');
                }
            }
        }, '-', {
            text: '启用',
            iconCls: 'icon-ok',
            handler: function () {
                let selected = $('#booklist').datagrid('getSelected');
                if (!selected) {
                    alert("请选择要修改状态的用户");
                } else {
                    $.ajax({
                        url: "/manager/user/status/1",
                        data: {
                            "id": selected.id
                        },
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.status !== 2001) {
                                alert(data.msg);
                            } else {
                                $('#booklist').datagrid('reload');
                            }
                        }
                    });
                }
            }
        }, '-', {
            text: '禁用',
            iconCls: 'icon-cancel',
            handler: function () {
                let selected = $('#booklist').datagrid('getSelected');
                if (!selected) {
                    alert("请选择要修改状态的用户");
                } else {
                    $.ajax({
                        url: "/manager/user/status/-1",
                        data: {
                            "id": selected.id
                        },
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.status !== 2001) {
                                alert(data.msg);
                            } else {
                                $('#booklist').datagrid('reload');
                            }
                        }
                    });
                }
            }
        }];
        $(function () {
            $("#search_type").val("");
            $("#keyword").val("");
            $('#booklist').datagrid({
                title: '用户列表',
                iconCls: 'icon-save',
                url: '/manager/user/findAll',
                columns: [
                    [
                        {field: 'id', hidden: true},
                        {field: 'username', title: '姓名', width: 100, align: 'center'},
                        {field: 'phone', title: '电话', width: 200, align: 'center'},
                        {field: 'email', title: 'eamil', width: 200, align: 'center'},
                        {
                            field: 'flag',
                            title: '状态',
                            width: 200,
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value === 1) {
                                    return "启用";
                                }
                                return "禁用";
                            }
                        },
                        {field: 'interest', hidden: true}
                    ]
                ],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20]
            });

            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    $('#booklist').datagrid({
                            queryParams: {
                                "keyword": $("#keyword").val(),
                                "flag": $("#search_type").val()
                            }
                    });   //点击搜索
                });

            //初始化修改窗口
            $('#dd').dialog({
                title: '用户修改',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $("#ff").form({
                            url: "user/modifyUser",
                            success: function (data) {
                                $('#dd').dialog('close');
                                alert(JSON.parse(data).msg);
                                $('#booklist').datagrid('reload');
                            }
                        })
                        $("#ff").submit();

                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog('close');

                    }
                }]
            });

        });
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>用户查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" size=20 placeholder="姓名" id="keyword"/>
        <select name="search_type" id="search_type">
            <option value="">所有</option>
            <option value="1">启用</option>
            <option value="-1">禁用</option>
        </select>
    </td>
    <td>
        <a id="submit_search">搜索</a>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="modify-id" name="id" type="hidden">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="modify-name" name="name" style="width:50%"
                       data-options="label:'姓名:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="phone" id="modify-phone" style="width:50%"
                       data-options="label:'电话:',required:true,validType:'phone'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="email" id="modify-email" style="width:50%"
                       data-options="label:'email:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="interest" id="modify-interest" style="width:50%;height:60px"
                       data-options="label:'兴趣爱好:',multiline:true">
            </div>
        </form>
    </div>
</div>
</body>
</html>